package dao

import java.sql.SQLException
import java.sql.PreparedStatement
import java.sql.Connection

public interface DAO <T> {
    
    /*public static final String SQL_INSERT;
    public static final String SQL_SELECT;
    public static final String SQL_SELECT_All;
    public static final String SQL_DELETE;*/
    
    /* Every method takes a connection object as a parameter.
     * The connection object has to be created by the caller which is also
     * responsible for commiting if the connection doesn't automatically.
     * The connection is to be created using DBConnection.establishConnection().
     */
    
    /* 
     * Persists the object to the database and returns its ID.
     * Returns -1 on error.
     */
    abstract Integer create(T object, Connection C ) throws SQLException
    
    /* 
     * Removes the specified object from the database and returns
     * true if the operation is succesful.
     */
    abstract Boolean remove(T object, Connection C) throws SQLException
    
    /* 
     * Updates the instance of the provided object on the database.
     * Returns false if an error occurs.
     */
    abstract Boolean update(T object, Connection C) throws SQLException
    
    /* 
     * Returns the object with the specified ID or null on error
     */
    abstract T find(Integer id, Connection C) throws SQLException
    
    /*
     * Returns a list with all the instances of class T found on the database
     * or null if the database is empty.
     */
    abstract List findAll(Connection C) throws SQLException
    
    /* 
     * Returns a list of the objects on the database matching the fields
     * of the provided object which are not null. Returns null on error
     * or if no objects were found.
     */
    abstract List select_by_property(String Camp, String value, Connection C) throws SQLException
    
    // void Closed(PreparedStatement ps) throws SQLException 
}

